#include "CharacterList.h"

namespace LightPlayer{

	CharacterList::CharacterList(){
		init();
	}

	void CharacterList::init(){
		m_shapes.clear();
		m_Sprites.clear();
		m_Bitmaps.clear();
		m_dictionary.clear();
	}

	// Getter of character from dictionary

	Character* CharacterList::getCharacter(uint16 characterId){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( characterId );
		if( it != m_dictionary.end() ){
			return it->second.pCharacter;
		}
		return NULL;
	}

	Shape* CharacterList::getShape(uint16 characterId){
		return (Shape*)( getCharacter(characterId) );
	}

	SPRITE_DEFINITION* CharacterList::getSprite(uint16 characterId){
		return (SPRITE_DEFINITION*)( getCharacter(characterId) );
	}

	Bitmap* CharacterList::getBitmap(uint16 characterId){
		return (Bitmap*)( getCharacter(characterId) );
	}


	Font* CharacterList::getFont( uint16 characterId )	{
		return (Font*)( getCharacter(characterId) );
	}


	StaticText* CharacterList::getStaticText( uint16 characterId ){
		return (StaticText*)( getCharacter(characterId) );
	}


	// Store of character in dictionary

	void CharacterList::StoreShapeInDictionary( Shape* shape ){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( shape->getCharacterId() );
		if( it == m_dictionary.end() ){
			m_dictionary[ shape->getCharacterId() ] = dictionaryCharacterInfo( eShapeCharacter, shape );
		}
		else{
			assert( 0 );
		}
	}

	void CharacterList::StoreSpriteInDictionary( SPRITE_DEFINITION* sprite ){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( sprite->getCharacterId() );
		if( it == m_dictionary.end() ){
			m_dictionary[ sprite->getCharacterId() ] = dictionaryCharacterInfo( eSpriteCharacter, sprite );
		}
		else{
			assert( 0 );
		}
	}

	void CharacterList::StoreBitmapInDictionary( Bitmap* bitmap ){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( bitmap->getCharacterId() );
		if( it == m_dictionary.end() ){
			m_dictionary[ bitmap->getCharacterId() ] = dictionaryCharacterInfo( eBitmapCharacter, bitmap );
		}
		else{
			assert( 0 );
		}
	}

	void CharacterList::StoreFontInDictionary( Font* font ){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( font->getCharacterId() );
		if( it == m_dictionary.end() ){
			m_dictionary[ font->getCharacterId() ] = dictionaryCharacterInfo( eFontCharacter, font );
		}
		else{
			assert( 0 );
		}
	}


	void CharacterList::StoreStaticTextInDictionary( StaticText* text ){
		dictionary<uint16,dictionaryCharacterInfo>::iterator it = m_dictionary.find( text->getCharacterId() );
		if( it == m_dictionary.end() ){
			m_dictionary[ text->getCharacterId() ] = dictionaryCharacterInfo( eStaticTextCharacter, text );
		}
		else{
			assert( 0 );
		}
	}


	// creation of Character from pool

	Shape* CharacterList::createShapeDef(){
		Shape* newObj = m_shapes.getNew();
		newObj->init();
		return newObj;
	}

	SPRITE_DEFINITION* CharacterList::createSpriteDef(){
		SPRITE_DEFINITION* newObj = m_Sprites.getNew();
		newObj->init();
		return newObj;
	}

	Bitmap* CharacterList::createBitmapDef(){
		Bitmap* newObj = m_Bitmaps.getNew();
		newObj->init();
		return newObj;
	}


	Font* CharacterList::createFontDef(){
		Font* newObj = m_Fonts.getNew();
		newObj->init();
		return newObj;
	}

	StaticText* CharacterList::createStaticTextDef(){
		StaticText* newObj = m_StaticTexts.getNew();
		newObj->init();
		return newObj;
	}

};